// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database()

// 云函数入口函数
exports.main = async (event, context) => {
  console.log(event);
  // 先取出集合记录总数
  const countResult = await db.collection('questions').count()
  const total = countResult.total
  const res1 = await db.collection('questions').where({
    examid: event.examid,
    typecode: '01'
  }).get()

  const res2 = await db.collection('questions').where({
    examid: event.examid,
    typecode: '02'
  }).get()


  const res3 = await db.collection('questions').where({
    examid: event.examid,
    typecode: '03'
  }).get()


  return {
    data1: res1.data,
    data2: res2.data,
    data3: res3.data,
    total: total
  }
}